package org.cupk2.service.lucene.doc;

import com.cupk2.lucene.document.CupkDocument;
import lombok.Data;
import org.cupk2.base.domain.CupkUserContext;
import org.cupk2.service.lucene.doc.enums.DocumentTitleEnum;
import org.cupk2.service.lucene.doc.enums.IndexModelEnum;

/**
 * 知识索引文档构造器
 */
@Data
public class KnowIndexDocument {

    private CupkDocument doc = new CupkDocument();

    public KnowIndexDocument(String id, IndexModelEnum model, String knowId, String title, String text, String fileId) {
        doc.addString(DocumentTitleEnum.id.name(), id);
        doc.addString(DocumentTitleEnum.model.name(), model.name());
        doc.addString(DocumentTitleEnum.knowId.name(), knowId);
        doc.addText(DocumentTitleEnum.title.name(), title);
        doc.addString(DocumentTitleEnum.fileId.name(), fileId);
        doc.addText(DocumentTitleEnum.text.name(), text);
    }

    public KnowIndexDocument(String id, IndexModelEnum model, String knowId, String title, String text) {
        doc.addString(DocumentTitleEnum.id.name(), id);
        doc.addString(DocumentTitleEnum.model.name(), model.name());
        doc.addString(DocumentTitleEnum.knowId.name(), knowId);
        doc.addText(DocumentTitleEnum.title.name(), title);
        doc.addText(DocumentTitleEnum.text.name(), text);
    }

    public KnowIndexDocument setUser(CupkUserContext user) {
        doc.addString(DocumentTitleEnum.userKey.name(), user.getLoginname());
        doc.addString(DocumentTitleEnum.userName.name(), user.getName());
        return this;
    }

    public KnowIndexDocument setTag(String tagKeys, String tagtitles) {
        doc.addText(DocumentTitleEnum.tagKeys.name(), tagKeys);
        doc.addText(DocumentTitleEnum.tagTitles.name(), tagtitles);
        return this;
    }

    public KnowIndexDocument setTime(String etime) {
        doc.addString(DocumentTitleEnum.etime.name(), etime);
        return this;
    }

    public CupkDocument getDoc() {
        return doc;
    }
}
